package com.example.base.demo.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

/**
 * @author TangDan
 * @version 1.0
 * @since 2023/3/14
 */
public class MyCondition implements Condition {

    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();// 获取环境对象
        String property = environment.getProperty("pearl.enabled");// 获取属性
        return !StringUtils.isEmpty(property) && Boolean.parseBoolean(property); // 存在配置并且为true
    }
}
